//添加购物车JS文件
$(function(){
	//当点击添加
	$('#addCart').click(function(){
		var goodsData = $('#buy').serialize();
		var combine = $('input[name=combine]').val();
		if(!combine){
			hd_alert({
				message:'请选择尺码和颜色',
				timeout:3
			});
		}else{
			$.ajax({
				url:ajaxCart,
				data:goodsData,
				dataType:'json',
				type:'post',
				success:function(phpData){
					if(phpData.status==0){
						hd_alert({
							message:phpData.message,
							timeout:3
						});
					}else{
						$('.cartMsg').show();
						$('.count').html(phpData.data.total);
						$('.carNum').html(phpData.data.total);
						$('.countmoney').html(phpData.data.totalmoney);
					}
								
				}
			})
		}
		
	})

//拖动购物车提示窗口

	  var dragging = false;
            var iX, iY;
            $(".cartMsg").mousedown(function(e) {
                dragging = true;
                iX = e.clientX - this.offsetLeft;
                iY = e.clientY - this.offsetTop;
                this.setCapture && this.setCapture();
                return false;
            });
            document.onmousemove = function(e) {
                if (dragging) {
                var e = e || window.event;
                var oX = e.clientX - iX;
                var oY = e.clientY - iY;
                $(".cartMsg").css({"left":oX + "px", "top":oY + "px"});
                return false;
                }
            };
            $(document).mouseup(function(e) {
                dragging = false;
                $(".cartMsg")[0].releaseCapture();
                e.cancelBubble = true;
            })
            
		//当点击X时关闭当前窗口
		$('.titleright').click(function(){
			$(this).parents('.cartMsg').hide();
		})
		//当点击继续购物关闭当前窗口
		$('.keepshop').find('a').click(function(){
			$(this).parents('.cartMsg').hide();
		})
 });


